package com.wm.exam.service.impl;

import com.wm.exam.dao.PaperMapper;
import com.wm.exam.pojo.Paper;
import com.wm.exam.service.PaperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PaperServiceImpl implements PaperService {
    @Autowired
    private PaperMapper paperMapper;


    /**
     * 添加试卷信息
     * @param paper
     * @return
     */
    @Override
    public int addPaper(Paper paper) {
        Paper newPaper = new Paper();
        newPaper.setA(paper.getA());
        newPaper.setB(paper.getB());
        newPaper.setC(paper.getC());
        newPaper.setD(paper.getD());
        newPaper.setCategoryId(paper.getCategoryId());
        newPaper.setStatus(1);
        newPaper.setTitle(paper.getTitle());
        newPaper.setTrueAnswer(paper.getTrueAnswer());
        return paperMapper.insertSelective(newPaper);
    }

    /**
     * 查询试题总数
     * @param uuid
     * @return
     */
    @Override
    public int getByUUID(String uuid) {
        return paperMapper.getByUUID(uuid);
    }

    /**
     * 查询试题详情
     * @param uuid
     * @return
     */
    @Override
    public List<Paper> getByPaperUUID(String uuid) {
        return paperMapper.getByPaperUUID(uuid);
    }

    /**
     * 根据id更新
     * @param paper
     * @return
     */
    @Override
    public int updateById(Paper paper) {
        Paper newPaper = new Paper();
        newPaper.setTitle(paper.getTitle());
        newPaper.setA(paper.getA());
        newPaper.setB(paper.getB());
        newPaper.setC(paper.getC());
        newPaper.setD(paper.getD());
        newPaper.setId(paper.getId());
        newPaper.setTrueAnswer(paper.getTrueAnswer());
        return paperMapper.updateByPrimaryKeySelective(newPaper);
    }

    /**
     * 根据id删除
     * @param deleteId
     * @return
     */
    @Override
    public int deleteById(Integer deleteId) {
        return paperMapper.deleteByPrimaryKey(deleteId);
    }
}
